package io.gimo.study.design_pattern.proxy.dynamic_proxy.jdk_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class TimeHandler implements InvocationHandler {

	private Object target;
	
	public TimeHandler(Object target){
		super();
		this.target = target;
	}
	
	/**
	 * 
	 * @param proxy 被代理对象
	 * @param method 被代理对象的方法
	 * @param args 方法参数
	 * @return 
	 * @throws Throwable
	 */
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		long start = System.currentTimeMillis();
		System.out.println("start");
		
		method.invoke(target);
		
		long over = System.currentTimeMillis();
		System.out.println("over");
		System.out.println("time is " +(over-start)+" ms");
		
		return null;
	}

}
